import { dataSourceType } from './../../type.d';
import { defineAsyncComponent } from 'vue';
//defineComponent 不能再批量引入组件时使用
interface obj {
  [propName: string]: any
}
const vueFiles = import.meta.glob('../draggable/**/*.vue'); // 异步方式
let comps: obj = {};
const configFiles: any = import.meta.globEager('../draggable/**/config.ts')
const formConfigFiles: any = import.meta.globEager('../draggable/**/formConfig.ts')

for (const [key, value] of Object.entries(vueFiles)) {

  const name = key.slice(key.lastIndexOf('/') + 1, key.lastIndexOf('.'));
  comps[name] = defineAsyncComponent(value);
}

let configSetting: dataSourceType[] = []
let formConfigSetting: dataSourceType[] = []
Object.keys(configFiles).forEach((item: string) => {
  const value = configFiles[item]
  configSetting.push(value.default.component.settings)
})
Object.keys(formConfigFiles).forEach((item: any) => {
  const value = formConfigFiles[item]
  formConfigSetting = formConfigSetting.concat(value.itemForm)
})


export { comps, configSetting, formConfigSetting }
